var api = require('../../utils/api.js');
var app = getApp();


Page({

    /**
     * 页面的初始数据
     */
    data: {
        status: -1,
        lists: []
    },

    seelist(ret) {
        console.log(ret);
        this.setData({
            lists: [],
            status: ret.currentTarget.dataset.i
        })

        this.getmyorder();
    },

    onLoad(ret) {

        this.setData({
            status:ret.status
        })

        this.getmyorder();
    },
    getmyorder() {
        var that = this;
        var status = this.data.status;

        api.post({
            url: 'order/getorderlist',
            data: {
                status: status
            },
            success: data => {
                that.setData({
                    lists: data.data
                })
            }
        })
    },

    seeorderbyid(ret) {
        console.log(ret);
        var id = ret.currentTarget.dataset.id;
        wx.navigateTo({
            url: '/pages/order/info?id=' + id
        })
    },
    deleteorder(ret) {
        var id = ret.currentTarget.dataset.id;
        var that = this;

        wx.showModal({
            title: '删除订单',
            content: '确认要删除订单？',
            complete: (res) => {
                if (res.confirm) {
                    wx.showLoading();
                    api.post({
                        url: 'order/deletebyid',
                        data: {id: id },
                        success: data => {
                            wx.hideLoading();
                            wx.showToast({
                                title: data.msg,
                                icon: 'none'
                            })
                            that.getmyorder();
                        }
                    })
                }
            }
        })

    },

    payorder(ret) {
        var id = ret.currentTarget.dataset.id;
        var that = this;
        // 支付
        api.post({
            url: 'order/paybyid',
            data: {
                id: id
            },
            success: data => {
                console.log(data);
                wx.requestPayment({
                    timeStamp: data.data.timeStamp,
                    nonceStr: data.data.nonceStr,
                    package: data.data.package,
                    signType: 'MD5',
                    paySign: data.data.paySign,
                    success(res) {
                        that.getmyorder();
                    }
                })
            }
        })
    },

    backmoney(ret){
     

        var id = ret.currentTarget.dataset.id;
        var that=this;
        // 退款

        wx.showModal({
            title: '退款',
            content: '确认要进行退款',
            complete: (res) => {
                if (res.confirm) {
                    api.post({
                        url: 'order/doRefund',
                        data: {oid:id,types:0},
                        success: data => {
                            console.log(data);
                            that.getmyorder();

                            wx.showToast({
                            title: data.msg,
                            icon:'none'
                            })
                        }
                    })
                }
            }
        })


     
    },

    backmoneys(ret){
     

        var id = ret.currentTarget.dataset.id;
        var that=this;
        // 退款

        wx.showModal({
            title: '退款',
            content: '当前退款将支付违约金',
            complete: (res) => {
                if (res.confirm) {
                    api.post({
                        url: 'order/doRefund',
                        data: {oid:id,types:1},
                        success: data => {
                            console.log(data);
                            that.getmyorder();

                            wx.showToast({
                            title: data.msg,
                            icon:'none'
                            })
                        }
                    })
                }
            }
        })


     
    }



})